<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" xmlns:shiro="http://www.pollix.at/thymeleaf/shiro">
<head>
    <th:block th:include="include :: header('辖区异常记录报警')"/>
    <th:block th:include="include :: datetimepicker-css"/>
</head>
<body class="gray-bg">
<div class="container-div">
    <div class="row">

        <div class="col-sm-12 select-table table-striped">
            <table id="bootstrap-table" lay-filter="bootstrap-table"></table>
        </div>
    </div>
</div>

<!--  开始日期 - 结束日期  合并  -->
<script type="text/html" id="toolbarDate">
    <div class="layui-inline">
        <label class="layui-form-label ">日期</label>
        <div class="layui-input-inline input-lang">
            <input type="text" class="layui-input layui-input-date" id="toolbarDate_layui">
        </div>
        <button type="button" lay-event="submits" class="layui-btn layui-btn-primary">查询</button>
    </div>
</script>

<!--  开始日期 - 结束日期  两个  -->
<script type="text/html" id="toolbarDate2">
    <div class="layui-inline ">
        <label class="layui-form-label ">日期：</label>
        <div class="layui-input-inline input-short">
            <input type="text" class="layui-input layui-input-date" id="toolbarDate_layui_2_start">
        </div>
        <div class="layui-input-inline "> ~ </div>
        <div class="layui-input-inline input-short">
            <input type="text" class="layui-input layui-input-date" id="toolbarDate_layui_2_end">
        </div>

        <button type="button" lay-event="submits" class="layui-btn layui-btn-primary">查询</button>
    </div>
</script>

<script type="text/html" id="titleTpl">
    <a href="/detail/{{d.id}}" class="layui-table-link">{{d.d1}}</a>
</script>


<th:block th:include="include :: footer"/>
<th:block th:include="include :: datetimepicker-js"/>
<script th:inline="javascript">

    // var prefix = ctx + "yf/reports/statistical";
    var prefix = ctx + "yf/warning";

    var districtsId = [[${districtsId}]];
    var deptType = [[${deptType}]];

    // 时间
    var range = $.tableTemplate.dateValue("range"),
        startDate = $.tableTemplate.dateValue("start"),
        endDate = $.tableTemplate.dateValue('end');


    if (!districtsId) {
        layer.msg("当前机构未设置管理区域")
    }
    layui.use(['table', 'laydate'], function () {
        var laydate = layui.laydate,
            table = layui.table,
            config = {
                toolbar: true,   // 工具控件   "#toolbarDate"   "#toolbarDate2"
                page: false,    // 开启分页
                totalRow: true  // 合计
            },
            // 卫健委及以上 表头
            cols_city = [[
                {
                    field: 'districtName',
                    align: 'center',
                    title: '下辖',
                    width: '10%',
                    totalRowText: '合计',
                    templet: function (row) {
                        if (row.districtDeep < 3)
                            return '<span lay-event="check" style="text-decoration: underline;color: #3636ad;">' + row.districtName + '</span>';
                        else
                            return row.districtName;
                    }
                },
                {
                    field: 'districtDeptNum',
                    align: 'center',
                    width: '12%',
                    title: '医疗机构数量',
                    totalRowType: 'int',
                    totalRow: true
                },
                {
                    field: 'isHospitalWarn',
                    align: 'center',
                    width: '12%',
                    title: '异常机构数量',
                    totalRowType: 'int',
                    totalRow: true
                },
                {
                    field: 'isOverdueMaxStoreWarn',
                    align: 'center',
                    title: '积存量超出预警值的机构数量',
                    totalRowType: 'int',
                    totalRow: true
                },
                {
                    field: 'isOverdueNoInputWarn',
                    align: 'center',
                    title: '24小时未录入医废的机构数量',
                    totalRowType: 'int',
                    totalRow: true
                },
                {
                    field: 'isOverdueNoInYFWarn',
                    title: '收集超过24小时未入库的机构数量',
                    totalRowType: 'int',
                    align: 'center',
                    totalRow: true
                },
                {
                    field: 'isOverdueNoOutYFWarn',
                    title: '入库超过48小时未出库的机构数量',
                    totalRowType: 'int',
                    align: 'center',
                    totalRow: true
                }
            ]
            ],

            //  卫健局表头
            cols_hosp = [[
                {
                    field: 'numbers',
                    align: 'center',
                    title: '序号',
                    totalRowText: '合计',
                    width: 150,
                    type: 'numbers'
                },
                {
                    field: 'hospitalName',
                    align: 'center',
                    title: '医疗机构名称',
                    minWidth: 200,
                    totalRow: false
                },
                // {
                //     field: 'stagingName',
                //     align: 'center',
                //     minWidth: 200,
                //     title: '暂存点名称',
                //     totalRow: false
                // },
                // {
                //     field: 'maxStore',
                //     align: 'center',
                //     title: '预警值（kg）',
                //     totalRow: true
                // },
                // {
                //     field: 'inStoreWeight',
                //     align: 'center',
                //     title: '暂存量（kg）',
                //     totalRow: true
                // },
                {
                    field: 'warnNum',
                    title: '预警数',
                    align: 'center',
                    totalRowType: 'int',
                    totalRow: true
                },
                {
                    field: 'isOverdueMaxStoreWarn',
                    title: '积存量超出预警值',
                    align: 'center',
                    totalRowType: 'int',
                    totalRow: true,
                    templet: function (row) {
                        if ( row.isOverdueMaxStoreWarn === 1 )
                            return '<img src="../../img/yujingtubiao.png" height="20" width="20">';
                        else
                            return '<span> - </span>';
                    }
                },
                {
                    field: 'isOverdueNoInputWarn',
                    title: '超过24小时未录入医废',
                    align: 'center',
                    totalRowType: 'int',
                    totalRow: true,
                    templet: function (row) {
                        if ( row.isOverdueNoInputWarn === 1 )
                            return '<img src="../../img/yujingtubiao.png" height="20" width="20">';
                        else
                            return '<span> - </span>';
                    }
                },
                {
                    field: 'isOverdueNoInYFWarn',
                    title: '收集超过24小时未入库',
                    align: 'center',
                    totalRowType: 'int',
                    totalRow: true,
                    templet: function (row) {
                        if ( row.isOverdueNoInYFWarn === 1 )
                            return '<img src="../../img/yujingtubiao.png" height="20" width="20">';
                        else
                            return '<span> - </span>';
                    }
                },
                {
                    field: 'isOverdueNoOutYFWarn',
                    title: '入库超过48小时未出库',
                    align: 'center',
                    totalRowType: 'int',
                    totalRow: true,
                    templet: function (row) {
                        if ( row.isOverdueNoOutYFWarn === 1 )
                            return '<img src="../../img/yujingtubiao.png" height="20" width="20">';
                        else
                            return '<span> - </span>';
                    }
                }
            ]
            ];


        // 判断是否是卫健局登录
        var tablehead;
        if ( deptType != null && deptType != '' ) {
            if( deptType === '130' ){
                tablehead = cols_hosp;
            }else{
                tablehead = cols_city;
            }
        }else{
            tablehead = cols_city;
        }


        table.render($.extend({
                elem: '#bootstrap-table',
                method: 'post',
                title: '辖区异常记录报警',
                url: prefix + "/districtsWarnStatusList",  // 数据接口
                method: 'post',
                where: {
                    disId: districtsId,
                    startDate: startDate,
                    endDate: endDate
                },
                cols: tablehead,
                defaultToolbar: [
                    {
                        title: '返回',  //标题
                        layEvent: 'REPLY',  //事件名，用于 toolbar 事件中使用
                        icon: 'layui-icon-return' //图标类名
                    },
                    'filter',
                    'exports',       // exports_custom
                    'print'
                ],
                parseData: $.tableTemplate.parseData(),
                done: function (res, curr, count) {
                    $.tableTemplate.done(res, curr, count, config);
                }
            }, config)
        );

        // 表格内监听
        table.on('tool(bootstrap-table)', function (obj) { //注：tool 是工具条事件名，test 是 table 原始容器的属性 lay-filter="对应的值"
            var data = obj.data; //获得当前行数据
            var layEvent = obj.event; //获得 lay-event 对应的值（也可以是表头的 event 参数对应的值）
            var tr = obj.tr; //获得当前行 tr 的 DOM 对象（如果有的话）
            if (layEvent === 'check') { //点击 body > div.container-div > div > div > div > div.layui-table-box > div.layui-table-header > table > thead > tr > th:nth-child(1) > div
                // layer.msg('check', {time: 2000});
                if (data.districtDeep === 0) {
                    // cols_city[0][0].title = '市';
                    table.reload("bootstrap-table", {
                        where: {
                            disId: data.districtId,
                            startDate: startDate,
                            endDate: endDate
                        }
                    }); //重载表格
                } else if (data.districtDeep === 1) {
                    // cols_city[0][0].title = '县';
                    table.reload("bootstrap-table", {
                        where: {
                            disId: data.districtId,
                            startDate: startDate,
                            endDate: endDate
                        }
                    }); //重载表格
                } else if (data.districtDeep === 2) {
                    table.render($.extend({
                            elem: '#bootstrap-table',
                            method: 'post',
                            title: '辖区异常记录报警',
                            url: prefix + "/districtsWarnStatusList",   // 数据接口
                            method: 'post',
                            where: {
                                disId: data.districtId,
                                startDate: startDate,
                                endDate: endDate
                            },
                            cols: cols_hosp,
                            defaultToolbar: [
                                {
                                    title: '返回',  // 标题
                                    layEvent: 'REPLY',  // 事件名，用于 toolbar 事件中使用
                                    icon: 'layui-icon-return'     // 图标类名
                                },
                                'filter',
                                'exports',
                                'print'
                            ],
                            parseData: $.tableTemplate.parseData(),
                            done: function (res, curr, count) {
                                $.tableTemplate.done(res, curr, count, config);
                            }
                        }, config)
                    );
                }
            }
        });
        //  表格工具栏监听
        table.on('toolbar(bootstrap-table)', function (obj) {
            var data = obj.data; //获得当前行数据
            var layEvent = obj.event; //获得 lay-event 对应的值（也可以是表头的 event 参数对应的值）
            var tr = obj.tr; //获得当前行 tr 的 DOM 对象（如果有的话）

            if (layEvent === 'REPLY') {

                table.render($.extend({
                        elem: '#bootstrap-table',
                        method: 'post',
                        title: '下辖',
                        url: prefix + "/districtsWarnStatusList",  // 数据接口
                        method: 'post',
                        where: {
                            disId: districtsId,
                            startDate: startDate,
                            endDate: endDate
                        },
                        cols: tablehead,
                        defaultToolbar: [
                            {
                                title: '返回',  //标题
                                layEvent: 'REPLY',  //事件名，用于 toolbar 事件中使用
                                icon: 'layui-icon-return' //图标类名
                            },
                            'filter',
                            'exports',
                            'print'
                        ],
                        PrExData: {
                            PrTitle: "辖区异常记录报警",
                            ExTitle: "辖区异常记录报警",
                            header: [    //  ${start} 到 ${end}    ${toolbarDate_layui_2_start} 到 ${toolbarDate_layui_2_start}
                                {
                                    type: "date",
                                    float: "left",
                                    size: 10,
                                    dateFormat: "yyyy/MM/dd",
                                    show: true,
                                    text: ""
                                }
                            ]
                        },
                        parseData: $.tableTemplate.parseData(),
                        done: function (res, curr, count) {
                            $.tableTemplate.done(res, curr, count, config);
                        }
                    }, config)
                );


                // cols_city[0][0].title = '省';
                // table.reload("bootstrap-table", {
                //     cols: tablehead,
                //     where: {
                //         disId: districtsId,
                //         startDate: startDate,
                //         endDate: endDate
                //     }
                // }); //重载表格

            } else if (layEvent === 'submits') {

                alert( 'submits' );

                table.reload('bootstrap-table', {
                    cols: tablehead,
                    where: {
                        startDate: startDate,
                        endDate: endDate
                    }
                });
            }
        });


    });


</script>
</body>
</html>